<?php

namespace app\controllers;

use Yii;
use yii\web\Controller;
use yii\web\Request;
use yii\web\Response;
use proxy\HttpProxy;
use helper\SessionHelper;
use helper\MenuHelper;

class SecBaseController extends BaseController
{
    public $proxy = null;
    public $session = null;    
    public $headers = null;    
    

    public function beforeAction($action)
    {
        parent::beforeAction($action);
        
        $check = $this->session->check($this->auth);
        if ($check['status'] == 0) {
            //add safe menu list to return page value
            //$this->session->set("menus", MenuHelper::getAssignedMenu($this->session->get('admin_user_id')));
            //$this->return_page_values = array_merge($this->return_page_values, ["menus" => MenuHelper::getAssignedMenu($this->session->get('admin_user_id'))]);
            $this->return_page_values = array_merge($this->return_page_values, ["menus" => $this->session->get("menus")]);
        } else if ($check['status'] == 1) {
            Yii::$app->response->data = $this->myRedirect('/login');
            return false;//return false to response from beforeAction, only format=json will go to here
        } else if ($check['status'] == 2) {
            Yii::$app->response->data = $this->myRedirect('/nopermission');
            return false;//return false to response from beforeAction, only format=json will go to here
        } else {
            Yii::$app->response->data = $this->myRedirect('/login');
            return false;//return false to response from beforeAction, only format=json will go to here
        }
          
        return true;
    }
    
}
